<template>
  <div class="message" @click="handleClick">
    <el-badge :value="msgStore.msgData.total" class="item">
      <i :class="'iconfont icon-xiaoxi'" class="toolBar-icon" />
    </el-badge>
    <!-- <el-popover placement="bottom" :width="310" trigger="click">
      <template #reference>
      </template>
      <el-tabs v-model="activeName">
        <el-tab-pane :label="`通知(${msgStore.msgData.notification?.total || 0})`" name="first">
          <div class="message-list">
            <div class="message-item" v-for="item in msgStore.msgData.notification?.row" :key="item.id">
              <img src="@/assets/images/msg01.png" alt="" class="message-icon" />
              <div class="message-content">
                <span class="message-title">{{ item.title }}</span>
                <span class="message-date">{{ item.createdAt }}</span>
              </div>
            </div>
            <div class="message-empty" v-show="msgStore.msgData.notification?.total == 0">
              <img src="@/assets/images/notData.png" alt="notData" />
              <div>暂无消息</div>
            </div>

            <!-- <div class="message-item">
              <img src="@/assets/images/msg04.png" alt="" class="message-icon" />
              <div class="message-content">
                <span class="message-title">一键三连 Sz-Admin 💜</span>
                <span class="message-date">一星期前</span>
              </div>
            </div>
            <div class="message-item">
              <img src="@/assets/images/msg05.png" alt="" class="message-icon" />
              <div class="message-content">
                <span class="message-title">一键三连 Sz-Admin 💛</span>
                <span class="message-date">一个月前</span>
              </div>
            </div> 
          </div>
        </el-tab-pane>
        <el-tab-pane :label="`消息(${msgStore.msgData.message?.total || 0})`" name="second">
          <div class="message-list">
            <div class="message-item" v-for="item in msgStore.msgData.message?.row" :key="item.id">
              <img src="@/assets/images/msg02.png" alt="" class="message-icon" />
              <div class="message-content">
                <span class="message-title">{{ item.title }}</span>
                <span class="message-date">{{ item.createdAt }}</span>
              </div>
            </div>
          </div>
          <div class="message-empty" v-show="msgStore.msgData.message?.total == 0">
            <img src="@/assets/images/notData.png" alt="notData" />
            <div>暂无消息</div>
          </div>
        </el-tab-pane>
        <el-tab-pane :label="`代办(${msgStore.msgData.waitdo?.total || 0})`" name="third">
          <div class="message-list">
            <div class="message-item" v-for="item in msgStore.msgData.waitdo?.row" :key="item.id">
              <img src="@/assets/images/msg03.png" alt="" class="message-icon" />
              <div class="message-content">
                <span class="message-title">{{ item.title }}</span>
                <span class="message-date">{{ item.createdAt }}</span>
              </div>
            </div>
          </div>
          <div class="message-empty" v-show="msgStore.msgData.waitdo?.total == 0">
            <img src="@/assets/images/notData.png" alt="notData" />
            <div>暂无代办</div>
          </div>
        </el-tab-pane>
      </el-tabs>
    </el-popover> -->
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { useMessageStore } from '@/stores/modules/sysMsg';
import { useRouter } from 'vue-router';
// const activeName = ref('first');
const msgStore = useMessageStore();
const route = useRouter();
onMounted(async () => {
  await msgStore.setMsgData();
});

const handleClick = () => {
  route.push('/message');
};
</script>

<style scoped lang="scss">
.message-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 260px;
  line-height: 45px;
}

.message-list {
  display: flex;
  flex-direction: column;

  .message-item {
    display: flex;
    align-items: center;
    padding: 5px 0;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;

    &:last-child {
      border: none;
    }

    .message-icon {
      width: 30px;
      height: 30px;
      margin: 0 10px 0 5px;
    }

    .message-content {
      display: flex;
      flex-direction: column;

      .message-title {
        margin-bottom: 5px;
      }

      .message-date {
        font-size: 12px;
        color: var(--el-text-color-secondary);
      }
    }
  }
}
</style>
